package com.jlu.test.batch;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;

public class ESTest_Insert_Delete {

  public static void main(String[] args) throws IOException {

//    创建es客户端
    RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(new HttpHost("localhost",9200, "http"))
    );

//    批量删除数据

    BulkRequest request = new BulkRequest();

    request.add(new DeleteRequest().index("user").id("1001"));
    request.add(new DeleteRequest().index("user").id("1002"));
    request.add(new DeleteRequest().index("user").id("1003"));

    BulkResponse response = client.bulk(request, RequestOptions.DEFAULT);

    System.out.println(response.getTook());

//    关闭es客户端
    client.close();
  }
}
